$(function(){
	// 点击返回按钮返回上一页
    $(".goBack").bind("click", function() {
        // window.history.back();location.reload();	//强行刷新
        // window.history.go(-1);  //返回上一页
        window.location.href = document.referrer; //返回上一页并刷新
    });
	// 轮播图
	$.ajax({
		type:"post",
		url:"http://a.91jfk.com/Product/Pic/index",
		async:true,
		data:{
			classify:1
		},
		dataType:'json',
		success:function(res){
			console.log(res);
			if(res.code == '1'){
				var msg = res.msg;
				var imgArr = [];
				for(var i = 0;i < msg.length;i++){
					imgArr.push(msg[i].pic);
				}
				// 轮播图
				var Swiper = new SwiperLunBo();
				Swiper.carousel(imgArr).swiper().changeLunBo(imgArr);		//changeLunBo方法只能在swiperLunBo方法之后调用
			}else{
				console.log(123);
			}
		},
		error:function(err){
			console.log(err);
		}
	});
	
	//进入页面加载列表数据
	getShow();
	function getShow(){
	 	$.ajax({
	        url:"http://a.91jfk.com/Product/Pointexchange/goods_list?platform=1&type=2",
	        type:'get',
	        dataType:'json',
	        success:function (res) {
	            console.log(res);
	            if(res.code == "1"){
	                var msg = res.message;
	                for(var i = 0;i < msg.length;i++){
	                	if (msg[i].exchange_point == '0') {
	                		DHgoodShow(msg[i].id,res.nowpage,msg[i].show_pic,msg[i].pname,msg[i].low_price,msg[i].point_price);
							$('img.lazy'+res.nowpage).lazyload({
								placeholder:"/Public/Product/img/loading2.gif",
								effect: "fadeIn",
								container: $(".jfGoodsList_box")
							});
	                	} else{
	                		DHgoodShow(msg[i].id,res.nowpage,msg[i].show_pic,msg[i].pname,msg[i].low_price,msg[i].exchange_point);
	                		$('img.lazy'+res.nowpage).lazyload({
								placeholder:"/Public/Product/img/loading2.gif",
								effect: "fadeIn",
								container: $(".jfGoodsList_box")
							});
	                	}
	                }
	            }else{
	                console.log(res.message);
	            }
	        },
	        error:function (err) {
	            console.log(err);
	        }
	    });
	}
	 
    //点击我的集分
    $(".content_con .lt").bind("click",function(){
    	console.log("点击我的集分");
    	window.location.href = 'page_wodejifen.html';
    });
    //点击兑换集分币
    $(".content_con .con").bind("click",function(){
    	console.log("点击兑换集分币");
    	window.location.href = 'page_jifenkaduihuan.html';
    });
    //点击兑换记录
    $(".content_con .rt").bind("click",function(){
    	console.log("点击兑换记录");
    	window.location.href = 'page_duihuanjilu.html';
    });
    
    function DHgoodShow(val,j,src,title,price,jf){
    	var parents = $('.list_row');
    	var father = $('<div class="list_col"></div>');
    	var input = $('<input type="hidden" value="'+ val +'"/>');
		var child = $('<div class="img_box"><img class="IMG lazy'+ j +'" src="/Public/Product/img/loading2.gif" data-original="' + src + '"/></div><p class="good_tit">'+ title +'</p><div class="priceORjf"><p class="price_JF"><span>&yen;'+ price +'</span><span>+' + jf + '集分</span></p></div>');
    	parents.append(father.append(input).append(child));
    }
    //点击商品列表，跳转详情界面
    $('.list_row').on('click',".list_col",function(){
    	var id = $(this).find("input[type=hidden]").val();
    	console.log("跳转，带上商品ID=" + id);
    	window.location.href = "jfdhDetail.html?id=" + id;
    });
});